#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2021/7/27 14:52
# @Author  : ldh

from basic.device.Android import Android

class AGXMyPage(Android):

    myBtm = "cn.cloudbae.loveguangxi:id/menu_my"  # 我的
    goLogin = "cn.cloudbae.loveguangxi:id/tvUserGoLogin"  # 我的页面，【登录】按钮
    userID="cn.cloudbae.loveguangxi:id/tvUserId" #用户id
    gotoMyInfo="cn.cloudbae.loveguangxi:id/gotoMyInfoEditLinearLayout" #个人信息
    right_text="cn.cloudbae.loveguangxi:id/item_right_text"
    nick_edit="cn.cloudbae.loveguangxi:id/nick_edit" #昵称
    nick_submit="cn.cloudbae.loveguangxi:id/nick_submit"

    #打开我的页面
    @classmethod
    def openMyPage(cls):
        cls.poco(cls.myBtm).click()

    #判断用是否已登录
    @classmethod
    def ifLogin(cls):
       if cls.poco(cls.goLogin).exists():
           return False
       else:
           return True

    #未登录，打开登录页去登录
    @classmethod
    def openLoginPage(cls):
        cls.poco(cls.goLogin).click()

    #已登录，获取用户ID
    @classmethod
    def getUserID(cls):
        userIDView=cls.poco(cls.userID)
        if userIDView.exists():
            id=userIDView.get_text().replace("ID","").replace(" ","")
            print("id:"+id)
        return id

    #查看个人信息
    @classmethod
    def myInfo(cls):
        cls.poco(cls.gotoMyInfo).click()

    @classmethod
    def getMyTelephone(cls):
        mytelephone=cls.poco(cls.right_text)[1].get_text()
        print("账号/手机号："+ mytelephone)
        return mytelephone

    #查看昵称
    @classmethod
    def nickName(cls):
        nickname=cls.poco(cls.right_text)[2].get_text()
        print("昵称："+nickname)
        return nickname

    #修改昵称
    @classmethod
    def editNickName(cls):
        cls.poco(cls.right_text)[2].click()
        cls.poco(cls.nick_edit).set_text("测试时的昵称")
        cls.poco(cls.nick_submit).click()
        nickname_new=cls.poco(cls.right_text)[2].get_text()
        print("修改昵称为："+ nickname_new)

    #还原昵称
    @classmethod
    def nickNameBack(cls):
        nickname=cls.poco(cls.right_text)[2].get_text()
        if nickname!="巴扎嘿":
            cls.poco(cls.right_text)[2].click()
            cls.poco(cls.nick_edit).set_text("巴扎嘿")
            cls.poco(cls.nick_submit).click()
        nickname=cls.poco(cls.right_text)[2].get_text()
        print("昵称恢复为："+ nickname)




